package com.jic.data.service.impl;
import java.util.*;
import java.util.stream.Collectors;

import cn.hutool.core.date.DateUtil;
import com.jic.data.constant.consist.ResponseCode;
import com.jic.data.exception.AppRuntimeException;
import com.jic.data.model.vo.response.SaleDetailResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import javax.annotation.Resource;
import java.math.BigDecimal;
import com.jic.data.model.vo.response.MonOneMoreGuestDetailCategoryResponse;
import com.jic.data.model.entity.MonOneMoreGuestDetailCategory;
import com.jic.data.mapper.MonOneMoreGuestDetailCategoryMapper;
import com.jic.data.service.MonOneMoreGuestDetailCategoryService;

import lombok.extern.slf4j.Slf4j;
/**
 * 接口实现类
 *
 * @author : 建投数据科技(山东)有限公司
 * @version : v1.0.0
 * @email :
 * @since : 2020-03-09 10:12:20
 */
@Service
@Slf4j
public class MonOneMoreGuestDetailCategoryServiceImpl implements MonOneMoreGuestDetailCategoryService {

	@Resource
	private MonOneMoreGuestDetailCategoryMapper mapper;


	/**
	 * 月度品类销售明细
	 *
	 * @param request 不分页查询入参实体类
	 * @return 数据库查到的实体类列表
	 */
	@Override
	public List<MonOneMoreGuestDetailCategory> listAllRecord(MonOneMoreGuestDetailCategory request) {

		List<SaleDetailResponse<List<MonOneMoreGuestDetailCategoryResponse>>> saleDetailResponse = new ArrayList<>();

		List<MonOneMoreGuestDetailCategory> list =  mapper.selectBySelective(request);
//		Map<Date, List<MonOneMoreGuestDetailCategory> > groupby
//				= list.stream().collect(Collectors.groupingBy(MonOneMoreGuestDetailCategory :: getSaleDate));
//
//		groupby.keySet().forEach(key -> {
//			SaleDetailResponse<List<MonOneMoreGuestDetailCategoryResponse>> responses = new SaleDetailResponse();
//			responses.setDate(DateUtil.format(key,"yyyy年MM月"));
//
//			List<MonOneMoreGuestDetailCategory> groupDatas = groupby.get(key);
//
//			List<MonOneMoreGuestDetailCategoryResponse> grouplist = groupDatas.stream().map(temp -> {
//				MonOneMoreGuestDetailCategoryResponse bo = new MonOneMoreGuestDetailCategoryResponse();
//				BeanUtils.copyProperties(temp, bo);
//				return bo;
//			}).filter(item -> item != null).collect(Collectors.toList());
//
//			responses.getList().add(grouplist);
//			saleDetailResponse.add(responses);
//		});
		return list;

	}

	@Override
	public List<MonOneMoreGuestDetailCategoryResponse> selectOneMoreInfo(MonOneMoreGuestDetailCategory request){
		List<MonOneMoreGuestDetailCategory> list = mapper.selectOneMoreInfo(request);
		List<MonOneMoreGuestDetailCategoryResponse> responseList = list.stream().map(temp -> {
			MonOneMoreGuestDetailCategoryResponse bo = new MonOneMoreGuestDetailCategoryResponse();
			Date saleDate = temp.getSaleDate();
			temp.setSaleDate(null);
			BeanUtils.copyProperties(temp, bo);
			bo.setSaleDate(DateUtil.format(saleDate, "yyyy年MM月"));
			return bo;
		}).filter(item -> item != null).collect(Collectors.toList());
		return responseList;
	}

}
